'''
Created on Jun 6, 2015

@author: geo
'''

from django.shortcuts import render

from django.core.paginator import Paginator as Pa, EmptyPage, InvalidPage

from models import Album as Al

def grabpage(request):
    albums = Al.objects.all()
    page_szie = 50
    pa = Pa(albums, page_szie)
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
    try:
        albums = pa.page(page) 
    except EmptyPage, InvalidPage:
        albums = pa.page(pa.num_pages) 
    return render(request, 'show_albums.html', {'albums':albums})

def showbycato(request, cato):
    albums = Al.objects.filter(genre = cato)
    page_szie = 50
    pa = Pa(albums, page_szie)
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1
    try:
        albums = pa.page(page) 
    except EmptyPage, InvalidPage:
        albums = pa.page(pa.num_pages) 
    return render(request, 'show_albums.html', {'albums' : albums})